<template>
  <el-dialog :visible.sync="formVisible" width="516px" @close="handleCancel">
    <div slot="title" class="dialog-title">{{title}}</div>
    <el-card class="el-card-border">
      <el-form :ref="formName" :model="formFieldsData" :rules="rules" label-width='100px' :label-position="labelPosition">
        <el-form-item label="上级类型：" prop="type_name">
          <el-select v-model="formFieldsData.parent_id" placeholder="请选择">
            <el-option key='0' label='顶级类型' value="0">
            </el-option>
            <el-option
              v-for="item in parentOptions"
              :key="item.id"
              :label="item.type_name"
              :value="item.id">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="类型名称：" prop="type_name">
          <el-input v-model="formFieldsData.type_name" clearable />
        </el-form-item>
        <el-form-item label="类型key：" prop="type_key">
          <el-input v-model="formFieldsData.type_key" clearable />
        </el-form-item>
        <el-form-item label="单选/多选：">
          <el-radio-group v-model="formFieldsData.select_type">
            <el-radio :label="1">单选</el-radio>
            <el-radio :label="0">多选</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="显示状态：">
          <el-radio-group v-model="formFieldsData.show_type">
            <el-radio :label="0">全部</el-radio>
            <el-radio :label="1">司机</el-radio>
            <el-radio :label="2">非司机</el-radio>
            <el-radio :label="3">企业</el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="排序：">
          <el-input v-model="formFieldsData.sort" type="number" clearable class="flex1"/>
        </el-form-item>
        <el-form-item label="是否必填：">
          <el-switch
            v-model="formFieldsData.is_require"
            :active-value="1"
            :inactive-value="0"
            class="switch_btn"
          />
        </el-form-item>
      </el-form>
    </el-card>
    <div slot="footer" class="dialog-footer">
      <el-button @click="handleCancel" size='medium'>取 消</el-button>
      <el-button type="primary" @click="handleSubmit" size='medium'>确 定</el-button>
    </div>
  </el-dialog>
</template>

<script>
import formOperate from '@/layout/mixin/formOperate'
export default {
  mixins: [formOperate],
  props:{
    parentOptions:{
      type:Array,
      default:()=>{
        return []
      }
    }
  },
  data() {
    return {
      url:'/profession/admin/tagType',
      isComponents:true,
      parent_name:'',
      formName: 'talentsAttr',
      formFieldsData: {
        type_name: '',
        parent_id:'0',
        type_key:'',
        select_type:1,
        show_type: 0,
        sort: 0,
        is_require:0
      },
      defaultQueryParam:['select_type','show_type','sort','is_require','parent_id'],
      // 验证规则
      rules: {
        type_name: [
          { required: true, message: '请输入类型名称', trigger: 'blur' },
          { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
        ],
        type_key: [
          { required: true, message: '请输入类型标记', trigger: 'blur' },
          { min: 1, max: 20, message: '长度在 1 到 20 个字符', trigger: 'blur' }
        ],
        sort: [
          { required: true, message: '请输入排序', trigger: 'blur' }
        ],
      }
    }
  },
  methods:{
    // 显示弹框
    show(row) {
      if(row) {
        this.formFieldsData.parent_id = row.id
        this.parent_name = row.type_name
      }
      this.formVisible = true
      this.formFieldsData.select_type = 1
      this.formFieldsData.show_type = 0
      this.formFieldsData.sort = 0
      this.formFieldsData.is_require = 0
      this.handleCreate()
    },
    // 新增和修改回调
    hiddenDialog() {
      this.formVisible = false
      this.$emit('getList')
    }
  }
}
</script>

<style>

</style>